const express = require("express");
const router = new express.Router();
const Employee_infos = require("../models/sc")
router.post("/Employee_info", async(req, res) => {
    const phone_lj = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
    const email_lj = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
    if (phone_lj.test(req.body.phone) && email_lj.test(req.body.email.trim())) {
        await Employee_infos.create(req.body)
        res.setHeader("Access-Control-Allow-Origin", "*");
        res.setHeader("Access-Control-Allow-Headers", "*");
        res.setHeader("Access-Control-Allow-Methods", "*");
        res.send("信息录入成功!!!!")
    } else {
        res.send("信息录入失败，重新录入")
    }
})
router.get("/kehu_cx", async(req, res) => {
    console.log(req.query);
    const result = await Employee_infos.find(req.query, {
        _id: 0,
        __v: 0
    });
    res.setHeader("Access-Control-Allow-Origin", "*");
    res.setHeader("Access-Control-Allow-Headers", "*");
    res.setHeader("Access-Control-Allow-Methods", "*");
    res.send(result);
})
router.post("/kehu_sc", async(req, res) => {
    await Employee_infos.remove({ Employee_id: req.body.Employee_id })
    res.setHeader("Access-Control-Allow-Origin", "*");
    res.setHeader("Access-Control-Allow-Headers", "*");
    res.setHeader("Access-Control-Allow-Methods", "*");
    res.send("删除成功")
})
module.exports = router;